from pydantic import BaseModel, validator
from datetime import date as date_type  # 重命名以避免冲突
from typing import Optional
from enum import Enum

class PaymentStatus(str, Enum):
    Y = 'Y'
    N = 'N'

class PaymentType(str, Enum):
    BOOK = 'BOOK'
    MEDI = 'MEDI'

class PaymentBase(BaseModel):
    patient_ID: int
    con_date: date_type  # 使用从datetime导入的date_type
    expense: int
    type: PaymentType
    pay_y_n: PaymentStatus
    ref_ID: int

    @validator('expense', )
    def validate_expense(cls, v):
        if v < 0:
            raise ValueError("费用不能为负数")
        return v

class PaymentCreate(PaymentBase):
    pass

class PaymentUpdate(BaseModel):
    patient_ID: Optional[int] = None
    con_date: Optional[date_type] = None  # 使用Optional[date_type]
    expense: Optional[int] = None
    type: Optional[PaymentType] = None
    pay_y_n: Optional[PaymentStatus] = None
    ref_ID: Optional[int] = None

    @validator('expense')
    def validate_expense(cls, v):
        if v is not None and v < 0:
            raise ValueError("费用不能为负数")
        return v

class PaymentResponse(PaymentBase):
    ID: int

    class Config:
        from_attributes = True